Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for parsing orbital moments from OUTCAR #3463

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

oashour
Copy link

@oashour oashour commented Nov 9, 2023

Summary

Major changes:

  • Add support for parsing orbital moments from OUTCAR
  • Update the magnetization parsing test to check orbital moments from OUTCAR.NiO_SOC.gz.

Todos

I opened this as a WIP since I have not contributed to pymatgen before, but it's technically complete. As far as I know, VASP does not write orbital moments anywhere besides OUTCAR, but if it does, I'd be happy to implement a parser if there's interest.

To minimize changes, I kept the code style consistent with the magnetization parsing in the Outcar class. However, it's a bit ugly due to the three extra boolean variables. I'm happy to rewrite that entire part to make it more compact.

The final thing to note is that the spin contribution to the magnetization is always with respect to SAXIS (there's a #TODO comment for that in the code), whereas orbital magnetization is always in Cartesian coordinates. Thus, the saxis property of the resultant Magmom objects for the orbital moments (the default [0 0 1]) is correct, but it's not generally correct for the spin contribution to the magnetic moments.

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy. (none needed)
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example) (not applicable)

@janosh
Copy link
Member

janosh commented Dec 5, 2023

@oashour Is this still WIP? If not, can you update the title?

@oashour oashour changed the title [WIP] Add support for parsing orbital moments from OUTCAR Add support for parsing orbital moments from OUTCAR Dec 5, 2023
@oashour
Copy link
Author

oashour commented Dec 5, 2023

@janosh done. The [WIP] tag was mainly because I'm a first-time contributor, and thought there might be some comments, but I have nothing to add to this unless someone spots a problem or possible improvement.

@janosh
Copy link
Member

janosh commented Feb 24, 2024

sorry this slipped. i forgot this is waiting on maintainer review.

However, it's a bit ugly due to the three extra boolean variables. I'm happy to rewrite that entire part to make it more compact.

if you can do that in a backwards compatible manner, that'd be much apprecciated!

@oashour
Copy link
Author

oashour commented Feb 24, 2024 via email

@janosh janosh added enhancement A new feature or improvement to an existing one io Input/output functionality vasp Vienna Ab initio Simulation Package labels Mar 11, 2024
Copy link

coderabbitai bot commented May 2, 2024

Walkthrough

The Outcar class in the pymatgen library has been enhanced to support reading and storing orbital moments for each ion in three dimensions (x, y, z). This update includes new attributes and logic for parsing these values from input files. Additionally, the testing suite has been updated to reflect these changes, ensuring that the new functionality is properly verified.

Changes

File Summary of Changes
.../io/vasp/outputs.py Updated Outcar class to include attributes and logic for handling orbital moments in three dimensions.
tests/io/vasp/test_outputs.py Expanded test_soc function to include additional checks for new orbital moment data.

Recent Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 45de1ae and c4b66a7.
Files selected for processing (2)
  • pymatgen/io/vasp/outputs.py (6 hunks)
  • tests/io/vasp/test_outputs.py (1 hunks)
Additional comments not posted (1)
pymatgen/io/vasp/outputs.py (1)

1981-2013: Check the logic for handling the reading of orbital moments. Ensure that the flags are set and reset correctly to avoid reading errors.

-        elif clean == "orbital moment (x)":
-            orbmom_x = []
-            read_orbmom_x = True
-            read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_y, read_orbmom_z = (
-                False,
-                False,
-                False,
-                False,
-                False,
-                False,
-            )
-        elif clean == "orbital moment (y)":
-            orbmom_y = []
-            read_orbmom_y = True
-            read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_z = (
-                False,
-                False,
-                False,
-                False,
-                False,
-                False,
-            )
-        elif clean == "orbital moment (z)":
-            orbmom_z = []
-            read_orbmom_z = True
-            read_charge, read_mag_x, read_mag_y, read_mag_z, read_orbmom_x, read_orbmom_y = (
-                False,
-                False,
-                False,
-                False,
-                False,
-                False,
-            )
+        # Ensure the logic for setting and resetting flags is correct and robust.
+        # This section needs careful review and potential refactoring for clarity and correctness.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@janosh
Copy link
Member

janosh commented May 2, 2024

i just resolved the merge conflicts. @oashour please ping us when this is ready to go

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Out of diff range and nitpick comments (2)
tests/io/vasp/test_outputs.py (2)

Line range hint 14-14: Ensure the TODO for adding tests is addressed or tracked in an issue.

Would you like me to help by generating the unit testing code or opening a GitHub issue to track this task?


Line range hint 25-27: Optimize the modulo operation.

-  while x >= y:
-    x -= y
-  return x
+  return x % y

Comment on lines 1772 to 1773
orbital_moment (tuple): Orbital moments on each ion as a tuple of dict, e.g.,
({"d": 0.109, "p": -0.001, "tot": 0.108}, ... )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the orbital_moment attribute is correctly documented and initialized.

-        orbital_moment (tuple): Orbital moments on each ion as a tuple of dict, e.g.,
+        orbital_moment: list = field(default_factory=list)  # Orbital moments on each ion as a list of dict, e.g.,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
orbital_moment (tuple): Orbital moments on each ion as a tuple of dict, e.g.,
({"d": 0.109, "p": -0.001, "tot": 0.108}, ... )
orbital_moment: list = field(default_factory=list) # Orbital moments on each ion as a list of dict, e.g.,
({"d": 0.109, "p": -0.001, "tot": 0.108}, ... )

Comment on lines 1839 to 1841
orbmom_x = []
orbmom_y = []
orbmom_z = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize orbmom_x, orbmom_y, and orbmom_z to handle orbital moments correctly.

-        orbmom_x = []
-        orbmom_y = []
-        orbmom_z = []
+        orbmom_x: list = field(default_factory=list)
+        orbmom_y: list = field(default_factory=list)
+        orbmom_z: list = field(default_factory=list)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
orbmom_x = []
orbmom_y = []
orbmom_z = []
orbmom_x: list = field(default_factory=list)
orbmom_y: list = field(default_factory=list)
orbmom_z: list = field(default_factory=list)

Comment on lines 1903 to 1905
read_orbmom_x = False # For SOC calculations with LORBMOM=.TRUE.
read_orbmom_y = False
read_orbmom_z = False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure read_orbmom_x, read_orbmom_y, and read_orbmom_z are initialized properly to handle reading orbital moments.

-        read_orbmom_x = False  # For SOC calculations with LORBMOM=.TRUE.
-        read_orbmom_y = False
-        read_orbmom_z = False
+        read_orbmom_x: bool = False  # For SOC calculations with LORBMOM=.TRUE.
+        read_orbmom_y: bool = False
+        read_orbmom_z: bool = False

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
read_orbmom_x = False # For SOC calculations with LORBMOM=.TRUE.
read_orbmom_y = False
read_orbmom_z = False
read_orbmom_x: bool = False # For SOC calculations with LORBMOM=.TRUE.
read_orbmom_y: bool = False
read_orbmom_z: bool = False

Comment on lines 1934 to 1936
read_orbmom_x = False
read_orbmom_y = False
read_orbmom_z = False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure flags for reading orbital moments are reset correctly.

-        read_orbmom_x = False
-        read_orbmom_y = False
-        read_orbmom_z = False
+        read_orbmom_x: bool = False
+        read_orbmom_y: bool = False
+        read_orbmom_z: bool = False

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
read_orbmom_x = False
read_orbmom_y = False
read_orbmom_z = False
read_orbmom_x: bool = False
read_orbmom_y: bool = False
read_orbmom_z: bool = False

@janosh janosh force-pushed the master branch 2 times, most recently from e3fbc67 to 41e6d99 Compare August 3, 2024 19:01
@oashour
Copy link
Author

oashour commented Sep 22, 2024

@janosh This should be good to go. I'm sorry it took so long--it's been hard to find the time to write the code I actually want to write.

The same approach could be used to clean up the code for the magnetization, but that should be done in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement to an existing one io Input/output functionality vasp Vienna Ab initio Simulation Package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants